package tptecnicas.logging;

/**
 * Clase encargada de proveer toda la informacion necesaria 
 * para el armado de cada reporte de log.
 */
public class MessageInfo {

	private final static String methodName = "logMessage";
	private final String message;
	private final String level;
	private final String separator;
	private int lineNumber;
	private String callerMethod;
	private String callerFilename;
	private final String loggerName;

	public MessageInfo(String message, String level, String separator, String loggerName) {
		super();
		this.message = message;
		this.level = level;
		this.separator = separator;
		this.loggerName = loggerName;
		StackTraceElement[] stackElements = Thread.currentThread().getStackTrace();
		findMethodInStack(stackElements);
	}


	private void findMethodInStack(StackTraceElement[] stackElements) {
		boolean found = false;
		int j = 0;
		while (!found && j < stackElements.length) {
			if (stackElements[j].getMethodName().equals(methodName)) {
				found = true;
			}
			j++;
		}
		if (found) {
			this.lineNumber = stackElements[j].getLineNumber();
			this.callerMethod = stackElements[j].getMethodName();
			this.callerFilename = stackElements[j].getFileName();
		}
	}

	public String getMessage() {
		return message;
	}

	public String getLevel() {
		return level;
	}

	public String getSeparator() {
		return separator;
	}

	public String getThread() {
		return Thread.currentThread().getName();
	}

	public int getLineNumber() {
		return lineNumber;
	}

	public String getCallerMethod() {
		return callerMethod;
	}

	public String getCallerFilename() {
		return callerFilename;
	}
	

	public String getLoggerName() {
		return loggerName;
	}
}
